<template>
  <el-container>
    <!-- 顶栏 -->
    <el-header height="120px">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      订单号:
      <el-input v-model="onumber" placeholder="请输入订单号" style="width:200px;"></el-input>日期:
      <el-date-picker
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="请选择日期"
        v-model="startTime"
        style="width:200px;"
      ></el-date-picker>至
      <el-date-picker
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="请选择日期"
        v-model="endTime"
        style="width:200px;"
      ></el-date-picker>收支类型:
      <el-select v-model="state" placeholder="请选择" style="width:200px">
        <el-option v-for="bean in stateList" :label="bean.name" :key="bean.id" :value="bean.id"></el-option>
      </el-select>
      <el-button type="success" @click="getList()" icon="el-icon-search">查询</el-button>
    </el-header>
    <!-- 嵌套容器 -->
    <el-container>
      <el-button type="text" @click="OrderFlag = true"></el-button>
      <el-dialog title="订单详情" :visible.sync="OrderFlag">
        <el-form :model="OrderList">
          <el-form-item label="订单号">
            <el-input v-model="OrderList.onumber" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="下单日期">
            <el-input v-model="OrderList.odate" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="预估运费">
            <el-input v-model="OrderList.freight" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="结算金额">
            <el-input v-model="OrderList.dsum" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="结算状态">
            <el-input v-model="OrderList.settle" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="OrderFlag = false">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 内容 -->
      <el-main>
        <!-- 第二列布局 -->
        <el-row>
          <el-col :span="30" class="col3">
            <el-table :data="tableData" stripe style="width: 100%">
              <el-table-column fixed type="index" label="序号" width="210px"></el-table-column>
              <el-table-column prop="onumber" label="订单号" width="210px"></el-table-column>
              <el-table-column prop="odate" label="下单日期" sortable width="205px"></el-table-column>
              <el-table-column prop="freight" label="预估运费" width="205px"></el-table-column>
              <el-table-column prop="dsum" label="结算金额" sortable width="205px"></el-table-column>
              <el-table-column fixed="right" label="结算状态" width="205px">
                <template slot-scope="scope">
                  <el-button v-if="scope.row.settle=='0'" @click="handleClick1(scope.row)">未结算</el-button>
                  <el-button v-if="scope.row.settle=='1'" @click="handleClick1(scope.row)">已结算</el-button>
                </template>
              </el-table-column>
              <el-table-column fixed="right" label="操作" width="210px">
                <template slot-scope="scope">
                  <el-button @click="handleClick(scope.row)" type="text" size="small">订单详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
    <!-- 底栏 -->
    <el-footer height="15px">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="[1, 2, 3, 4]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-footer>
  </el-container>
</template>

<script>
import axios from "axios";
export default {
  methods: {
    handleClick(row) {
      this.OrderFlag = true;
      this.OrderList = row;
    },
    handleClick1(row) {
      alert(row.settle);
      if (row.settle == 1) {
        this.axios({
          method: "post",
          url: "http://localhost:9999/finance/tmsOrder/update",
          params: {
            settle: 0,
            onumber: row.onumber,
            access_token: localStorage.getItem("access_token")
          }
        }).then(function(res) {
          location.reload();
        });
      } else {
        this.axios({
          method: "post",
          url: "http://localhost:9999/finance/tmsOrder/update",
          params: {
            settle: 1,
            onumber: row.onumber,
            access_token: localStorage.getItem("access_token")
          }
        }).then(function(res) {
          location.reload();
        });
      }
    },
    ss(val) {
      if (val.state == 1) {
        return "支出";
      } else if (val.state == 2) {
        return "收入";
      }
      return;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNo = val;
      this.getList();
    },
    getList() {
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/finance/tmsOrder/getList",
        params: {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          startTime: this.startTime,
          endTime: this.endTime,
          state: this.state,
          onumber: this.onumber,
          access_token: localStorage.getItem("access_token")
        }
      }).then(function(res) {
        $this.tableData = res.data.obj.list;
        $this.total = res.data.obj.total;
      });
    }
  },
  data() {
    return {
      OrderFlag: false,
      tableData: [],
      pageNo: 1,
      pageSize: 2,
      total: 10,
      onumber: "",
      startTime: "",
      endTime: "",
      state: "",
      stateList: [
        {
          id: "1",
          name: "支出"
        },
        {
          id: "2",
          name: "收入"
        }
      ],
      OrderList: []
    };
  },
  mounted() {
    this.getList();
  }
};
</script>
<style>
.el-pagination {
  text-align: center;
}
</style>
